<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Picture;
class GoodsGallery extends Model
{

    /**
     * 表名称
     * @var $table;
     */
    protected $table = 'goods_gallery';

    /**
     * 主键
     * @var $primaryKey
     */
    protected $primaryKey = 'goods_id';

    /**
     * 时间戳   laravel ORM 自动维护数据库时间戳,用户数据结构的回滚操作,默认开启,我们禁止
     * @var bool $timestamps
     */
    public $timestamps = false;
    protected $appends = array('mobile_pic_1','mobile_pic_2','mobile_pic_3','mobile_pic_4','mobile_pic_5','mobile_pic_6','mobile_pic_7','mobile_pic_8');

    /**
     * 自动填充字段
     * @var $fillable
     */
    protected $fillable = ['goods_id', 'pic_1', 'pic_2','pic_3','pic_4','pic_5','pic_6','pic_7','pic_8'];

    function getMobilePic1Attribute(){

        $pic_1 = $this->getAttribute('pic_1');

        if(!$pic_1){
            return null;
        }
        return Picture::find($pic_1)->url;

    }
    function getMobilePic2Attribute(){

        $pic_2 = $this->getAttribute('pic_2');
        if(!$pic_2){
            return null;
        }

        return Picture::find($pic_2)->url;

    }
    function getMobilePic3Attribute(){

        $pic_3 = $this->getAttribute('pic_3');

        if(!$pic_3){
            return null;
        }
        return Picture::find($pic_3)->url;

    }
    function getMobilePic4Attribute(){

        $pic_4 = $this->getAttribute('pic_4');
        if(!$pic_4){
            return null;
        }
        return Picture::find($pic_4)->url;

    }
    function getMobilePic5Attribute(){

        $pic_5 = $this->getAttribute('pic_5');
        if(!$pic_5){
            return null;
        }

        return Picture::find($pic_5)->url;

    }
    function getMobilePic6Attribute(){

        $pic_6 = $this->getAttribute('pic_6');
        if(!$pic_6){
            return null;
        }

        return Picture::find($pic_6)->url;

    }
    function getMobilePic7Attribute(){

        $pic_7 = $this->getAttribute('pic_7');
        if(!$pic_7){
            return null;
        }

        return Picture::find($pic_7)->url;

    }
    function getMobilePic8Attribute(){

        $pic_8 = $this->getAttribute('pic_8');
        if(!$pic_8){
            return null;
        }

        return Picture::find($pic_8)->url;

    }

}
